package com.zy.web.controller.business;

import com.zy.business.domain.TbDocumentFolder;
import com.zy.business.service.DocumentFolderService;
import com.zy.common.annotation.Log;
import com.zy.common.core.controller.BaseController;
import com.zy.common.core.domain.AjaxResult;
import com.zy.common.core.page.TableDataInfo;
import com.zy.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @description: 文档库管理接口
 * @author: whf
 * @create: 2023-02-24 14:55
 **/
@RestController
@Api(tags = "文档库管理接口")
@RequestMapping("/documentFolder")
public class DocumentFolderController extends BaseController {

    @Autowired
    private DocumentFolderService documentService;

    @ApiOperation("根据项目id分页获取文档库列表")
    @GetMapping("/list")
    public TableDataInfo list(Long projectId) {
        startPage();
        List<TbDocumentFolder> documentFolderList = documentService.list(projectId);
        return getDataTable(documentFolderList);
    }

    @ApiOperation(value = "添加文档库")
    @PostMapping("/add")
    @Log(title = "文档库管理", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody TbDocumentFolder documentFolder){
        documentFolder.setCreateBy(getUsername());
        return toAjax(documentService.addDocumentFolder(documentFolder));
    }

    @ApiOperation(value = "修改文档库")
    @PutMapping("/edit")
    @Log(title = "文档库管理", businessType = BusinessType.UPDATE)
    public AjaxResult edit(@RequestBody TbDocumentFolder documentFolder){
        documentFolder.setUpdateBy(getUsername());
        return toAjax(documentService.editDocumentFolder(documentFolder));
    }

    @ApiOperation(value = "删除文档库")
    @DeleteMapping("/delete/{id}")
    @Log(title = "文档库管理", businessType = BusinessType.DELETE)
    public AjaxResult delete(@PathVariable Long id){
        return toAjax(documentService.deleteDocumentFolder(id));
    }


}
